
#include <BScrollBar>
#include "member_BScrollBar.h"

using namespace BWE;

member_BScrollBar::member_BScrollBar(BScrollBar* scrollBar)
{
	boss = scrollBar;
	value = 0;
	page = 10;
	minimum = 0;
	maximum = 100;
	step = 1;
	orientation = Orientation_Horizontal;
	leftPress = false;
	draging = false;
	hoverHandle = false;
}
member_BScrollBar::~member_BScrollBar()
{

}

void member_BScrollBar::freshHandleRect()
{
	BRect crect = boss->clientRect();
	int cx = crect.x();
	int cy = crect.y();
	int cw = crect.width();
	int ch = crect.height();

	if(page > maximum - minimum)
		page = maximum - minimum;
	if (value < minimum)
		value = minimum;
	if (value > maximum - page)
		value = maximum - page;

	if(orientation == Orientation_Horizontal)
	{
		float range = maximum - minimum;
		int x = cx + cw * (value - minimum) / range;
		int w = cw * page / range;
		handleRect.set(x, cy, w, ch - 1);
	}
	if(orientation == Orientation_Vertical)
	{
		float range = maximum - minimum;
		int y = cy + ch * (value - minimum) / range;
		int h = ch * page / range;
		handleRect.set(cx, y, cw - 1, h);
	}
}
